﻿#ifndef CAMERAHIK_H
#define CAMERAHIK_H

#include "CameraBase.h"
#include <MvCameraControl.h>

#pragma execution_character_set("utf-8")
class CameraHik : public CameraBase
{
public:
    CameraHik();
    virtual ~CameraHik();
    // Camera interface
public slots:
    virtual void initialize()override;
    virtual void openCamera()override;
    virtual void startGrabbing()override;
    virtual void stopGrabbing()override;
    virtual void closeCamera()override;
    virtual void releaseCamera() override;
    virtual void preProcessImage(const ImageInfo& imgInfo)override;
    virtual QStringList enumCameraList()override;

    virtual void triggerSoftware()override;//软触发
    virtual void setFrameTriggerMode(const QString& camName, const CameraTriggerType &type) override;
    virtual void setFrameTriggerDelay(const QString& camName, const float &delay)override;
    virtual void setLineTriggerMode(const QString& camName, const CameraTriggerType &type)override;
    virtual void setTriggerMode(const QString &camName, const CameraTriggerType &type) override;

    //ROI
    virtual void setWidth(const QString& camName, const int& width)override;
    virtual void setHeight(const QString& camName, const int& height)override;
    virtual void setOffsetX(const QString& camName, const int& off_x)override;
    virtual void setOffsetY(const QString& camName, const int& off_y)override;
    //Trans
    virtual void setReverseX(const QString& camName, const bool& reverse_x)override;
    virtual void setReverseY(const QString& camName, const bool& reverse_y)override;
    //white balance
    virtual void setWhiteBalanceMode(const QString& camName, const int &mode)override;
    virtual void setWhiteBalanceR(const QString& camName, const int &wb_r)override;
    virtual void setWhiteBalanceG(const QString& camName, const int &wb_g)override;
    virtual void setWhiteBalanceB(const QString& camName, const int &wb_b)override;
    //Brightness
    virtual void setExposureAutoMode(const QString& camName, const int &expMode)override;
    virtual void setExposureTime(const QString& camName, const float &exp)override;
    virtual void setGainMode(const QString& camName, const int &gainMode)override;
    virtual void setGain(const QString& camName, const float &exp)override;

    //帧率控制
    virtual void setFrameRate(const QString& camName, const float &rate)override;
    virtual void setFrameRateControl(const QString& camName, const bool& control)override;

    //分倍频
    virtual void setPreDiv(const QString& camName, const int& preDiv) override;
    virtual void setMul(const QString& camName, const int& mul) override;
    virtual void setPostDiv(const QString& camName, const int& postDiv) override;

    virtual int getPixelFormat() override;
    virtual bool isColor(int pixelFormat) override;

    virtual int getScanType() override;
    virtual bool isLineScan(int scanType) override;

    //trigger
    virtual CameraTriggerType getFrameTriggerMode(const QString& camName) override;
    virtual FloatValue getFrameTriggerDelay(const QString& camName) override;
    virtual CameraTriggerType getLineTriggerMode(const QString& camName) override;
    virtual CameraTriggerType getTriggerMode(const int &mode, const int& source) override;
    //ROI
    virtual IntValue getWidth(const QString& camName) override;
    virtual IntValue getHeight(const QString& camName) override;
    virtual IntValue getOffsetX(const QString& camName) override;
    virtual IntValue getOffsetY(const QString& camName) override;
    //Trans
    virtual bool getReverseX(const QString& camName) override;
    virtual bool getReverseY(const QString& camName) override;

    //white balance
    virtual int getWhiteBalanceMode(const QString& camName) override;
    virtual IntValue getWhiteBalanceR(const QString& camName) override;
    virtual IntValue getWhiteBalanceG(const QString& camName) override;
    virtual IntValue getWhiteBalanceB(const QString& camName) override;
    //Brightness
    virtual int getExposureAutoMode(const QString& camName) override;
    virtual FloatValue getExposureTime(const QString& camName) override;
    virtual int getGainMode(const QString& camName) override;
    virtual FloatValue getGain(const QString& camName) override;
    //帧率控制
    virtual bool getFrameRateControl(const QString& camName) override;
    virtual FloatValue getFrameRate(const QString& camName) override;

    //分倍频
    virtual IntValue getPreDiv(const QString& camName) override;
    virtual IntValue getMul(const QString& camName) override;
    virtual IntValue getPostDiv(const QString& camName) override;

    //general
    void setNodeBool(const char* nodeName, bool bValue);
    void setNodeEnum(const char* nodeName, const int& nValue);
    void setNodeInt(const char* nodeName, const int& iValue);
    void setNodeFloat(const char* nodeName, const float& fValue);

    bool getNodeBool(const char* nodeName);
    int getNodeEnum(const char* nodeName);
    IntValue getNodeInt(const char* nodeName);
    FloatValue getNodeFloat(const char* nodeName);

    void execCommand(const char* nodeName);

    static void __stdcall ImageCallBackEx(unsigned char *pData,MV_FRAME_OUT_INFO_EX *pFrameInfo, void *pUser);
    static void __stdcall ExceptionCallBack(unsigned int nMsgType, void* pUser);
    static void __stdcall EventCallBack(MV_EVENT_OUT_INFO * pEventInfo, void* pUser);
    static void __stdcall EventCallBackFalling(MV_EVENT_OUT_INFO * pEventInfo, void* pUser);

private:
    void saveParamToUserSet();

private:
    void* mHandle = nullptr;
    unsigned int mTLayerType = 0;//设备类型 GIGE or USB
};

#endif // CAMERAHIK_H
